//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(requestName){
	window.location=contextRootPath+'/'+requestName+'/prepareExecute/toAdd2?contractCode='+parent.contractCode;
}
//新增页面的保存操作
function doAddFrom(requestName){
	if(!CheckUtil.formCheck("addNewsFormData")){
		return;
	}
	//序列化 新增页面的form表单数据
	var params=$("#addNewsFormData").serialize();
	var upperRequestName=requestName.charAt(0).toUpperCase()+requestName.slice(1);
	var url=contextRootPath+'/'+requestName+'/insert'+upperRequestName;
	//通过ajax保存
	jyAjax(
		url,
		params,
		function(msg){
			//新增成功后，
			alert(msg.msg);
			var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		//返回列表页
        		back(requestName);
        	}
  	});
}
//修改 事件
function toUpdateData(requestName){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待修改的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}
	
	window.location=contextRootPath+'/'+requestName+'/prepareExecute/toUpdate2?id='+v_ids;
}
//修改页面 的 保存操作
function doUpdateFrom(requestName){
	if(!CheckUtil.formCheck("addNewsFormData")){
		return;
	}
	//序列化 新增页面的form表单数据
	var params=$("#addNewsFormData").serialize();
	var upperRequestName=requestName.charAt(0).toUpperCase()+requestName.slice(1);
	var url=contextRootPath+'/'+requestName+'/update'+upperRequestName;
	//通过ajax保存
	jyAjax(
		url,
		params,
		function(msg){
			//保存成功后，执行查询页面查询方法
			alert(msg.msg);
        	var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		//新增成功后 刷新页面 或 只查询 id为msg.data['id'] 的  数据
        		back(requestName);
        	}
  	});
}
//删除 事件
function deleteData(requestName){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	var upperRequestName=requestName.charAt(0).toUpperCase()+requestName.slice(1);
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/"+requestName+"/delete"+upperRequestName+"?ids="+v_ids,
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframe.iframeObj["table"].removeSelectedRow();
            	}
            	
            	
            }
        });
    }
}
//查看明细
function viewData(requestName,vId){
	return;
	window.location=contextRootPath+'/'+requestName+'/prepareExecute/toUpdate2?id='+vId;
}


function save(requestName,isSure){
	var id=$("#dtoid").val();
	
	var repayType = $("#dtorepayType").val();
	var settleType = $("#dtosettleType").val();
	var replaceType = $("#dtoreplaceType").val();
	
	if(isSure){
		if(repayType && settleType && replaceType){
			if(id){
				doUpdateFrom(requestName);
			}else{
				doAddFrom(requestName);
			}
		}else{
			alert("月还处理方式、结算计算方式、月还还款方式为必填项！");
		}
	}else{
		if(id){
			doUpdateFrom(requestName);
		}else{
			doAddFrom(requestName);
		}
	}
	
}
function back(requestName){
	window.location=parent.$("#"+requestName).attr("href");
}

$(document).ready(function(){
	(parent.action=="view")&&($("#tableToolbar").empty())
});